home *** CD-ROM | disk | FTP | other *** search
/ Learn Microsoft Visual Basic 6.0 Now / Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO / media / chap05 / b05d005.cc2 < prev    next >
Text File  |  1998-06-07  |  2KB  |  54 lines

  1. 0, The If...Then decision structure is a 
  2. 3, useful tool for adding program logic to 
  3. 5, your application. In this demonstration 
  4. 8, you'll use an If...Then decision structure 
  5. 10, to validate users as they log into a 
  6. 12, program. With a little creativity, you can 
  7. 16, use this technique to password protect 
  8. 18, a network application or a stand-alone 
  9. 20, program that you want to protect from 
  10. 22, wandering eyes. First, I'll create a 
  11. 24, command button object on my form and give it 
  12. 27, the name LogIn. I'll enter the caption, 
  13. 33, LogIn, in the Properties window. Then, 
  14. 40, I'll shrink a few of my programming tools 
  15. 43, to make room for the Code window. I want 
  16. 45, to be able to see all the program code 
  17. 47, that I'm going to write. Next, I'll open 
  18. 51, the Command1_Click event procedure and 
  19. 55, use it now to create an If...Then 
  20. 57, decision structure that recognizes the users, 
  21. 59, Laura and Mark. Typing the program code 
  22. 63, will take just a few moments. This event 
  23. 75, procedure uses an InputBox function to 
  24. 78, prompt the user for their name and 
  25. 80, stores the name in the UserName variable. The 
  26. 85, event procedure then prompts the user 
  27. 86, for a login password and stores the 
  28. 89, password in the Pass variable. An If...Then 
  29. 93, decision structure then checks to see if 
  30. 95, the user name and password were either 
  31. 98, Laura and May 17th, or Mark and trek. If 
  32. 102, either conditional expression evaluates 
  33. 104, to True, a message box is displayed 
  34. 106, welcoming the validated user to the program. 
  35. 110, If either the user name or password does 
  36. 111, not match, the message "Sorry, I don't 
  37. 116, recognize you," is displayed on the 
  38. 117, screen. The program is then terminated with 
  39. 120, the Visual Basic End statement. The 
  40. 124, keywords in this decision structure are If, 
  41. 127, which tests a condition, Else If, which 
  42. 131, tests a second condition, and Else, 
  43. 135, which picks up the pieces if none of the 
  44. 136, conditional tests evaluates to True. Now, 
  45. 140, I'll run the program. When I click the 
  46. 149, Login button, two dialog boxes appear that 
  47. 152, prompted me for my name and my 
  48. 154, password. If I type a recognizable pair, I'm 
  49. 161, welcomed to the system. However, if I try 
  50. 165, again and type a pair that is not 
  51. 166, recognizable, I receive the message, "Sorry, I 
  52. 176, don't recognize you," and the program 
  53. 179, ends. Now, what was my password, anyway?
  54. 183, END